package application;

import ij.process.ByteProcessor;
import ij.process.ImageProcessor;

public class ToGrayScale {
	
	public ImageProcessor outputProcessor;
	
	public static ImageProcessor run(ImageProcessor ip){
		int[] iArray = {0,0,0};
		ByteProcessor bp = new ByteProcessor(ip.getWidth(),ip.getHeight());
		for(int i=0;i<ip.getHeight();i++){
			for(int j=0;j<ip.getWidth();j++){
				ip.getPixel(j, i, iArray );
				bp.putPixel(j, i, moyenne(iArray));
			}
		}
		return bp;
	}
	
	private static int moyenne(int[] array){
		int somme=0;
		for(int i : array){
			somme+=i;
		}
		return somme/array.length;
	}
	
}
